package cn.funeralobjects.ams.web.controller;

import cn.funeralobjects.ams.service.StsAccessKeyService;
import cn.funeralobjects.ams.web.api.StsAccessKeyApi;
import cn.funeralobjects.ams.web.mapper.StsAccessKeyMapper;
import cn.funeralobjects.ams.web.model.VStsAccessKey;
import cn.funeralobjects.ams.web.model.VStsAccessKeyParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author FuneralObjects
 * Create date: 2020/6/8 7:46 AM
 */
@RestController
@RequestMapping("/sts-access-key")
public class StsAccessKeyController implements StsAccessKeyApi {
    @Resource
    private StsAccessKeyService stsAccessKeyService;

    @Resource
    private StsAccessKeyMapper stsAccessKeyMapper;

    @PostMapping
    @Override
    public Mono<VStsAccessKey> createStsAccessKey(@RequestBody VStsAccessKeyParam stsAccessKeyParam) {
        return Mono.just(stsAccessKeyParam).map(param -> stsAccessKeyService.createStsAccessKeyByRole(param.getRoleSessionName(), param.getRoleId(), param.getProdResId(), stsAccessKeyMapper.toDto(param.getPolicy()), param.getDuration())).map(stsAccessKeyMapper::toVo);
    }
}
